package per.sunmes.cl.g.actor.ef;

import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.scenes.scene2d.Actor;

public class ShadowActor extends Actor {

	Actor target;

	public ShadowActor() {
	}

	public ShadowActor(Actor target) {
		this.target = target;
	}

	public Actor getTarget() {
		return target;
	}

	public void setTarget(Actor target) {
		this.target = target;
	}

	@Override
	public void draw(Batch batch, float parentAlpha) {
		if (target != null) {
			targetStoreSwitchAttributes();
			target.draw(batch, parentAlpha);
			revertTargetAttributes();
		}
	}

	private void revertTargetAttributes() {
		target.setPosition(x, y);
		target.setSize(width, height);
		target.setOrigin(originX, originY);
		target.setScale(scaleX, scaleY);
		target.setRotation(rotation);
	}

	float x, y, scaleX, scaleY, originX, originY, width, height, rotation;

	private void targetStoreSwitchAttributes() {
		x = target.getX();
		y = target.getY();
		width = target.getWidth();
		height = target.getHeight();
		originX = target.getOriginX();
		originY = target.getOriginY();
		scaleX = target.getScaleX();
		scaleY = target.getScaleY();
		rotation = target.getRotation();

		target.setPosition(getX(), getY());
		target.setSize(getWidth(), getHeight());
		target.setOrigin(getOriginX(), getOriginY());
		target.setScale(getScaleX(), getScaleY());
		target.setRotation(getRotation());
	}
}
